<template>
	<view class="content">
		<view class="re_block">
			<view class="tab">
				<picker style="width: 50%;" @change="setIn" :value="inType" :range="inList">
					<view class="tabbar">
						<text>{{ inList[inType] }}</text>
						<uni-icons type="arrowdown" :color="'#C5CFD5'" size="20"></uni-icons>
					</view>
				</picker>
				<view class="t_line"></view>
				<picker style="width: 50%;" @change="setOut" :value="outType" :range="outList" :range-key="'label'">
					<view class="tabbar">
						<text>{{ outList[outType].label }}</text>
						<uni-icons type="arrowdown" :color="'#C5CFD5'" size="20"></uni-icons>
					</view>
				</picker>
			</view>
			<template v-if="outType==0||outType==1">
				<view class="list">
					<view class="block" v-for="(item, index) in dList" :key="index">
						<view class="top">
							<view class="left">
								<text>{{coin}}</text>
								<view>ERC20</view>
							</view>
							<view class="right">{{ filter.fix(item.amount, 6) }}</view>
						</view>
						<view class="center">{{ item.transferOutAddress }}</view>
						<view class="btm">
							<view class="left">{{ $formta(item.updateDate, 'yyyy-MM-dd hh:mm') }}</view>
							<view class="right" v-if="item.status == 'SUCCESS'">充币成功</view>
							<view class="right" v-if="item.status == 'REFUSE'">已退还</view>
							<view class="right" v-if="item.status == 'PROCESSING'||item.status == 'WAIT'||item.status == 'UNKNOWN'">进行中</view>
							<view class="right" v-if="item.status == 'SUCCESS'">失败</view>
						</view>
					</view>
				</view>
				<view class="none" v-if="!dList[0]&&outType==1">
					<image src="../../../static/c2c/none.png" mode=""></image>
					<view>暂无记录</view>
				</view>
			</template>
			<template v-if="outType==0||outType==2">
				<view class="list">
					<view class="block" v-for="(item, index) in wList" :key="index">
						<view class="top">
							<view class="left">
								<text>{{coin}}</text>
								<view>ERC20</view>
							</view>
							<view class="right">{{ filter.fix(item.amount, 6) }}</view>
						</view>
						<view class="center">{{ item.transferOutAddress }}</view>
						<view class="btm">
							<view class="left">{{ $formta(item.updateDate, 'yyyy-MM-dd hh:mm') }}</view>
							<view class="right" v-if="item.status == 'SUCCESS'">充币成功</view>
							<view class="right" v-if="item.status == 'REFUSE'">已退还</view>
							<view class="right" v-if="item.status == 'PROCESSING'||item.status == 'WAIT'||item.status == 'UNKNOWN'">进行中</view>
							<view class="right" v-if="item.status == 'SUCCESS'">失败</view>
						</view>
					</view>
				</view>
				<view class="none" v-if="!wList[0]&&outType==2">
					<image src="../../../static/c2c/none.png" mode=""></image>
					<view>暂无记录</view>
				</view>
			</template>
			<template v-if="outType==0||outType==3">
				<view class="list">
					<view class="block" v-for="(item, index) in tranList" :key="index">
						<view class="top">
							<view class="left">
								<text>{{coin}}</text>
								<text class="blue">ERC20</text>
							</view>
							<view class="right">{{ item.quantity }}{{coin}}</view>
						</view>
						<view class="center">
							<text>币币账户</text>
							转入
							<text>算力账户</text>
						</view>
						<view class="btm">
							<view class="left">{{ $formta(item.createTime, 'yyyy-MM-dd hh:mm') }}</view>
							<view class="right" v-if="item.transStatus == 'SUCCESS'" >划转成功</view>
							<view class="right" v-if="item.transStatus == 'FAIL'" >划转失败</view>
							<view class="right" v-if="item.transStatus == 'UNKNOW'||item.transStatus == 'INIT'" >处理中</view>
						</view>
					</view>
				</view>
				<view class="none" v-if="!tranList[0]&&outType==3">
					<image style="margin-left: 330rpx;" src="../../../static/c2c/none.png" mode=""></image>
					<view>暂无记录</view>
				</view>
			</template>
			<view class="none" v-if="outType==0&&!dList[0]&&!wList[0]&&!tranList[0]">
				<image style="margin-left: 330rpx;" src="../../../static/c2c/none.png" mode=""></image>
				<view>暂无记录</view>
			</view>
		</view>
		<HMmessages ref="HMmessages" @complete="HMmessages = $refs.HMmessages"></HMmessages>
	</view>
</template>

<script>
import uniPagination from '@/components/uni-pagination/uni-pagination.vue';
import { uniLoadMore } from '@dcloudio/uni-ui';
import uniIcons from '@/components/uni-icon/uni-icon.vue';
import HMmessages from '@/components/HM-messages/HM-messages.vue';
import service from '../service.js';
import filter from '@/common/filter.js';
export default {
	components: {
		uniIcons,
		uniPagination,
		HMmessages,
		uniLoadMore
	},
	data() {
		return {
			filter,
			depositHeight: 0,
			withdrawHeight: 0,
			transferHeight: 0,
			coin: '',
			dPageNo: 1,
			dTotal: 1,
			dList: [],
			wPageNo: 1,
			tranPageNo: 1,
			wTotal: 1,
			tranTotal: 1,
			wList: [],
			tranList: [],
			tPageNo: 1,
			tTotal: 1,
			tList: [],
			aPageNo: 1,
			aTotal: 1,
			ttTotal: 0,
			aList: [],
			pageSize: 10,
			dloading: true,
			wloading: true,
			tloading: true,
			tranloading: true,
			aloading: true,
			inType: 0,
			outType: 0,
			inList: ['全部币种'],
			outList: [
				{
					type: 'all',
					label: '全部类型'
				},

				{
					type: 'd',
					label: '充值'
				},
				{
					type: 'w',
					label: '提币'
				},
				{
					type: 't',
					label: '划转'
				}
			]
		};
	},
	onShow() {
		if (this.$api.isLogin()) {
			this.getConfigSymbolRank();
			this.depositOutList();
			this.withdrawOutList();
			this.assetTransRecord();
			this.getActList();
			return false;
		}
		this.$api.goLogin('../../login/login');
	},
	methods: {
		//设置类型
		setIn(e) {
			this.inType = e.target.value;
			if(this.inType==0) {
				this.coin = 'all'
			} else {
				this.coin = this.inList[this.inType];
				this.depositOutList();
				this.withdrawOutList();
				this.assetTransRecord();
			}
		},
		setOut(e) {
			this.outType = e.target.value;
		},
		//获取活动资产变化
		getActList() {
			this.aloading = true;
			this.aList = [];
			service
				.getActList({
					pageNo: this.aPageNo,
					pageSize: this.pageSize,
					assetCode: this.coin
				})
				.then(({ data }) => {
					this.aloading = false;
					if (data.code == '100200') {
						this.aList = data.data.list;
						this.aTotal = data.data.pageNum;
					} else {
						this.errors(data.msg);
					}
				});
		},
		//切换
		setType(name) {
			this.pairs = name;
		},
		//获取币对
		getConfigSymbolRank() {
			service.getConfigSymbolRank().then(data => {
				this.symbol = data.data.data[0].assetCode1;
				for(let i =0;i<data.data.data.length;i++) {
					this.inList.push(data.data.data[i].assetCode2);
					
				}
			});
		},
		//查询充值记录
		depositOutList() {
			this.dloading = true;
			this.dList = [];
			service
				.depositOutList({
					pageNo: this.dPageNo,
					pageSize: this.pageSize,
					assetCode: this.coin
				})
				.then(({ data }) => {
					this.dloading = false;
					if (data.code == '100200') {
						console.log(data.data)
						this.dList = data.data.list;
						this.dTotal = data.data.pageNum;
					} else {
						this.errors(data.msg);
					}
				});
		},
		//查询提现记录
		withdrawOutList() {
			this.wloading = true;
			this.wList = [];
			service
				.withdrawOutList({
					pageNo: this.wPageNo,
					pageSize: this.pageSize,
					assetCode: this.coin
				})
				.then(({ data }) => {
					this.wloading = false;
					if (data.code == '100200') {
						this.wList = data.data.list;
						this.wTotal = data.data.pageNum;
					} else {
						this.errors(data.msg);
					}
				});
		},
		//云算力划转记录
		assetTransRecord() {
			this.tranloading = true;
			this.tranList = [];
			service
				.assetTransRecord({
					pageNo: this.tranPageNo,
					pageSize: this.pageSize,
					assetCode: this.coin
				})
				.then(({ data }) => {
					this.tranloading = false;
					if (data.code == '100200') {
						if (this.coin == 'USDT') {
							this.tranList = data.data.list;
							this.tranTotal = data.data.pageNum;
							this.ttTotal = data.data.total;
						}
					} else {
						this.errors(data.msg);
					}
				});
		},
		//错误提示
		errors(text) {
			this.HMmessages.show(text, {
				textAlign: 'center',
				background: '#74272d',
				fontColor: '#fff'
			});
		},
		//设置手风琴
		setHeight(name, height) {
			return false;
			let that = this;
			let view = uni.createSelectorQuery().select(`#${name}`);
			if (this[height] > 0) {
				this[height] = 0;
			} else {
				view.boundingClientRect(data => {
					that[height] = data.height;
				}).exec();
			}
		}
	}
};
</script>

<style lang="scss">
@import './style.scss';
</style>
